package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.user.UserOderService;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/user/order")
@Api(tags = "预计配送时间")
public class UserOderConterller {

    @Autowired
    private UserOderService userOderService;

    @GetMapping("/getEstimatedDeliveryTime")
    public Result getEstimatedDeliveryTime(Integer shopId,String customerAddress){
        log.info("预计送到时间：{},{}",shopId,customerAddress);
        LocalDateTime time = userOderService.getEstimatedDeliveryTime(shopId,customerAddress);
        return Result.success(time);
    }

    @PostMapping("/submit")
    public Result submit(@RequestBody OrdersSubmitDTO dto){
        log.info("用户下单：{}",dto);
        OrderSubmitVO orderSubmitVO = userOderService.submit(dto);
        return Result.success(orderSubmitVO);
    }

}
